/* store的 index.js页面 */
import Vue from 'vue'
import Vuex from 'vuex'







const state = {
  selfBaseData: {}, //基础数据
  scList: [], //收藏列表
  deptChoice: [], //部门选择
  xuequList: [], //学区列表
  metroList: [] //地铁列表
}





const getters = {
  //selfBaseData.userList
  //这是state.selfBaseData.userList数据通过 用户ID 得到 用户obj对象 的filter方法
  userIdGetUserObj: (state) => (userId) => {
    return state.selfBaseData.userList.find(val => val.id == userId)
  },
  deptIdGetDeptObj: (state) => (deptId) => {
    return state.selfBaseData.deptList.find(val => val.id == deptId)
  },
  pianquIdGetpianquObj: (state) => (pianquId) => {
    return state.selfBaseData.pianquList.find(val => val.id == pianquId)
  },
  //从basicSet对象中返回包含指定type值的对象
  basicSetFilterFun: (state) => (typeVal) => {
    return state.selfBaseData.basicSet.find(val => val.type == typeVal)
  }
}



const mutations = {
  baseDataFun(state, data) {
    state.selfBaseData = data
  },
  scListFun(state, data) {
    state.scList = data
  },
  deptChoiceFun(state, data) {
    state.deptChoice = data
  },
  xuequListFun(state, data) {
    state.xuequList = data
  },
  metroListFun(state, data) {
    state.metroList = data
  }
}
//store.commit('change1')



const Store = new Vuex.Store({
  state,
  getters,
  mutations
});


/* selfBaseDataFun().then(res=>{
  console.log(res)
}) */


export default Store;

